<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用 JSON 解析</title>
</head>

<body>
    <h1>用 JSON 字符串创建对象</h1>
    <p id="demo"></p>
    <script>
        var text = '{"employees":[' +
            '{"firstName":"Bill","lastName":"Gates" },' +
            '{"firstName":"Steve","lastName":"Jobs" },' +
            '{"firstName":"Elon","lastName":"Musk" }]}';

        obj = JSON.parse(text);
        document.getElementById("demo").innerHTML =
            obj.employees[1].firstName + " " + obj.employees[1].lastName;
    </script>
    </script>
</body>

</html>